package com.example.toy.core.writer;

import com.example.toy.core.commit.CommitType;

/**
 * WriteScope
 *
 * @author shenbing
 * @date 2021/12/27
 */
public enum WriteScope {
  table,
  partition,
  record;

  public static WriteScope fromCommitType(CommitType commitType) {
    switch (commitType) {
      case INSERT:
      case UPSERT:
      case UPDATE:
      case DELETE:
        return record;

      case INSERT_OVERWRITE:
        return table;

      case INSERT_OVERWRITE_PARTITION:
        return partition;

      case COMPACT:
      case INIT:
      case ALTER_COLUMN:
        throw new IllegalArgumentException("Unsupported commit type to write scope: " + commitType);
      default:
        throw new IllegalArgumentException("Unsupported commit type to write scope: " + commitType);
    }
  }

}
